<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>多个桌面</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #wrap{
            width: 500px;
            height: 500px;
            background: #f0f0f0;
            color: #666;
            margin: 20px auto;
            overflow: hidden;
            position: relative;
            /* display: inline-block; */
        }
        #conten{
            position: absolute;
            width: 1500px;
            height: 500px;
            z-index: 1;
            left: 0;
        }
        #conten #desk1{
            width: 500px;
            height: 500px;
            float: left;
        }
        #conten #desk2{
            width: 500px;
            height: 500px;
            float: left;
        }
        #conten #desk3{
            width: 500px;
            height: 500px;
            float: left;
        }
        #pre{
            left: 10px;
            top: 250px;
            position: absolute;
            cursor: pointer;
            z-index: 2
        }
        #next{
            right: 10px;
            top: 250px;
            position: absolute;
            cursor: pointer;
            z-index: 2;
        }
        #wrap2{
            width: 100%;
            height: 100vh;
            background: #666;
            position: relative;
            overflow: hidden;
            z-index: 1;
        }
        #conten2{
            width: 100%;
            height: 100vh;
            position: absolute;
            z-index: 3;

        }
        #conten2 #deskT1{
            width: 100%;
            height: 100vh;
            background: #000;
            z-index: 2;
        }
        #conten2 #deskT2{
            width: 100%;
            height: 100vh;
            background: blue;
            z-index: 2;
        }
        #conten2 #deskT3{
            width: 100%;
            height: 100vh;
            background: green;
            z-index: 2;
        }
        #conten2Button{
            z-index: 20;
            background: #666;
            width: 100px;
            height: 100px;
            left: 40%;
            top: 40%;
            color: #fff;
            position: absolute;
        }
    </style>
</head>
<body>
    <div id="wrap">
        <div id="conten">
            <div id="desk1">deskOne</div>
            <div id="desk2">deskTwo</div>
            <div id="desk3">deskThree</div>
        </div>
        <div id="pre">pre</div>
        <div id="next">next</div>
    </div>

    <div id="wrap2">
        <div id="conten2">
            <div id="deskT1"></div>
            <div id="deskT2"></div>
            <div id="deskT3"></div>
        </div>
        <div id="conten2Button"></div>
    </div>

    <script>
        //平铺计算偏移量
        (function(){
            let desk1 = getId('desk1'),
                desk2 = getId('desk2'),
                desk3 = getId('desk3'),
                conten = getId('conten'),
                pre = getId('pre'),
                next = getId('next');

            //Becase class do not import style.
            //So, define one.
            conten.style.left = 0;

            pre.onclick = function(){
                if(parseInt(conten.style.left) >= 0){
                    conten.style.left = '-1000px';
                }else{
                    let newPosition = parseInt(conten.style.left) + 500;
                    conten.style.left = newPosition + 'px';
                    console.log(parseInt(conten.style.left));
                }
                
            }

            next.onclick = function(){
                if(parseInt(conten.style.left) <= -1000){
                    conten.style.left = 0;
                }else{
                    let newPosition = parseInt(conten.style.left) - 500;
                    conten.style.left = newPosition + 'px';
                    console.log(parseInt(conten.style.left));
                }
            }
            
        })();
            
        //垂直计算偏移量
        (function(){
            let conten2 = getId('conten2'),
                conten2Button = getId('conten2Button');
            conten2.style.top = 0;
            conten2Button.onclick = function(){
                console.log(parseInt(conten2.style.top));
                if(parseInt(conten2.style.top) <= -(conten2.clientHeight*2)){
                    conten2.style.top = 0;
                }else {
                    conten2.style.top =(parseInt(conten2.style.top) - conten2.clientHeight) +'px';
                }
            }

        }());

        //fun
        function getId(id){
            return document.getElementById(id);
        }
    </script>
</body>
</html>